<template>
  <div class="box">
    <p class="p_title">
      <el-button type="text" style="float: left;color: #000;font-size: 16px">编辑模板信息</el-button>
    </p>
    <div style="margin-bottom: 30px;border-bottom: 2px solid rgb(242 242 242)">
      <el-row style="text-align: center;line-height: 40px;line-height: 40px;margin-bottom: 20px">
        <el-col :span="2"><span>模板名称</span></el-col>
        <el-col :span="6">
          <el-input placeholder="请输入模板名称" v-model="name"></el-input>
        </el-col>
      </el-row>
      <el-row style="text-align: center;line-height: 40px;line-height: 40px;margin-bottom: 20px">
        <el-col :span="2"><span>模板类型</span></el-col>
        <el-col :span="6">
          <el-select v-model="value" placeholder="请选择模板类型" style="width: 100%">
            <el-option
              v-for="item in options"
              :key="item.type"
              :label="item.typeName"
              :value="item.type">
            </el-option>
          </el-select>
        </el-col>
      </el-row>
    </div>
    <el-form>
      <p class="p-title">系统管理权限</p>
      <el-row style="border: 1px solid rgb(242 242 242);padding: 10px">
        <el-col :offset="2" :span="21">
          <el-checkbox-group v-model="roleListBox" @change="roleListEvent(roleListBox)" disabled>
            <el-checkbox
              v-for="data in roleList"
              :label="data.id"
              :key="data.id">
              {{data.name}}
            </el-checkbox>
          </el-checkbox-group>
        </el-col>
      </el-row>
      <p class="p-title">项目报建权限</p>
      <el-row style="border: 1px solid rgb(242 242 242);padding: 10px">
        <el-col :offset="2" :span="21">
          <el-checkbox-group v-model="checked" @change="listEvent(checked)">
            <el-checkbox
              v-for="data in Box1"
              :label="data.id"
              :key="data.id">
              {{data.name}}
            </el-checkbox>
          </el-checkbox-group>
        </el-col>
      </el-row>
      <p class="p-title">设计方案权限</p>
      <el-row style="border: 1px solid rgb(242 242 242);padding: 10px">
        <el-col :offset="2" :span="21">
          <el-checkbox-group v-model="checked" @change="listEvent(checked)">
            <el-checkbox
              v-for="data in Box2"
              :label="data.id"
              :key="data.id">
              {{data.name}}
            </el-checkbox>
          </el-checkbox-group>
        </el-col>
      </el-row>
      <p class="p-title">施工许可权限</p>
      <el-row style="border: 1px solid rgb(242 242 242);padding: 10px">
        <el-col :offset="2" :span="21">
          <el-checkbox-group v-model="checked" @change="listEvent(checked)">
            <el-checkbox
              v-for="data in Box3"
              :label="data.id"
              :key="data.id">
              {{data.name}}
            </el-checkbox>
          </el-checkbox-group>
        </el-col>
      </el-row>
      <p class="p-title">竣工验收权限</p>
      <el-row style="border: 1px solid rgb(242 242 242);padding: 10px">
        <el-col :offset="2" :span="21">
          <el-checkbox-group v-model="checked" @change="listEvent(checked)">
            <el-checkbox
              v-for="data in Box4"
              :label="data.id"
              :key="data.id">
              {{data.name}}
            </el-checkbox>
          </el-checkbox-group>
        </el-col>
      </el-row>
      <p class="p-title">咨询服务权限</p>
      <el-row style="border: 1px solid rgb(242 242 242);padding: 10px">
        <el-col :offset="2" :span="21">
          <el-checkbox-group v-model="checked" @change="listEvent(checked)">
            <el-checkbox
              v-for="data in Box5"
              :label="data.id"
              :key="data.id">
              {{data.name}}
            </el-checkbox>
          </el-checkbox-group>
        </el-col>
      </el-row>
      <p class="p-title">掘占路等咨询</p>
      <el-row style="border: 1px solid rgb(242 242 242);padding: 10px">
        <el-col :offset="2" :span="21">
          <el-checkbox-group v-model="checked" @change="listEvent(checked)">
            <el-checkbox
              v-for="data in Box6"
              :label="data.id"
              :key="data.id">
              {{data.name}}
            </el-checkbox>
          </el-checkbox-group>
        </el-col>
      </el-row>
      <p class="p-title">竣工验收提前查看</p>
      <el-row style="border: 1px solid rgb(242 242 242);padding: 10px">
        <el-col :offset="2" :span="21">
          <el-checkbox-group v-model="checked" @change="listEvent(checked)">
            <el-checkbox
              v-for="data in Box7"
              :label="data.id"
              :key="data.id">
              {{data.name}}
            </el-checkbox>
          </el-checkbox-group>
        </el-col>
      </el-row>
      <p class="p-title">事中事后监管权限</p>
      <el-row style="border: 1px solid rgb(242 242 242);padding: 10px">
        <el-col :offset="2" :span="21">
          <el-checkbox-group v-model="checked" @change="listEvent(checked)">
            <el-checkbox
              v-for="data in Box8"
              :label="data.id"
              :key="data.id">
              {{data.name}}
            </el-checkbox>
          </el-checkbox-group>
        </el-col>
      </el-row>
      <p class="p-title">掘占路等许可权限</p>
      <el-row style="border: 1px solid rgb(242 242 242);padding: 10px">
        <el-col :offset="2" :span="21">
          <el-checkbox-group v-model="checked" @change="listEvent(checked)">
            <el-checkbox
              v-for="data in Box9"
              :label="data.id"
              :key="data.id">
              {{data.name}}
            </el-checkbox>
          </el-checkbox-group>
        </el-col>
      </el-row>
    </el-form>
    <el-footer class="el_foot">
      <el-button type="primary" @click="SavePermissions">保存</el-button>
    </el-footer>
  </div>
</template>

<script>
  import {$aos} from '../../../store/state';
  import {http} from '../../../assets/commonjs/axios';


  export default {
    name: "templateEdit",
    data() {
      return {
        id: null,
        name: '',
        Box1: [],
        Box2: [],
        Box3: [],
        Box4: [],
        Box5: [],
        Box6: [],
        Box7: [],
        Box8: [],
        Box9: [],
        checked: [],
        options: [],
        value: '',
        account: $aos.account(),
        booleans: true,
        templateList: [],
        token: '',
        roleList: [], //1.项目信息 2.设计方案 3.施工许可 4.竣工验收 5.技术咨询 6.监管意见
        roleListBox: [],
      }
    },
    created() {
      this.getModil();
      this.getRoleAll(() => {
        $aos.getItem('templateData').then(res => {
          this.CheckInformation(res.id);
          this.id = res.id;
        });
      });
    },
    methods: {
      CheckInformation(id) {
        http('post', 'permission/operate_model', {
          applyType: 4,
          id: id
        }).then(res => {
          if (res.data.code === 200) {
            this.name = res.data.data.name;
            if (res.data.data.operationRights !== '') {
              let checked = res.data.data.operationRights.split(',');
              let roleListBox = res.data.data.directoryRights.split(',');
              this.value = res.data.data.type;
              let Array = [];
              let Brr = [];
              checked.forEach((item, index) => {
                Array.push(parseInt(item));
              });
              roleListBox.forEach((item, index) => {
                Brr.push(parseInt(item));
              });
              this.checked = Array;
              this.roleListBox = Brr;
            }
          }
        })
      },
      SavePermissions() {
        http('post', 'permission/operate_model', {
          applyType: 2,
          dirRights: this.roleListBox.toString(),
          opeRights: this.checked.toString(),
          name: this.name,
          type: this.value,
          id: this.id
        }).then(res => {
          if (res.data.success) {
            this.$message({message: res.data.msg, type: 'success'});
            this.$router.push({path: '/container'})
          } else {
            this.$message({message: res.data.msg, type: 'warning'});
          }
        })
      },
      listEvent(list) {
      },
      roleListEvent(list) {
      },
      getModil() {
        http('post', 'permission/list_model_type',).then(res => {
          if (res.data.success) {
            this.options = res.data.data;
          }
        })
      },
      getRoleAll(cb) {
        http('post', 'permission/list_rights').then(res => {
          if (res.data.success) {
            this.roleList = res.data.data.dirRights;
            let box = res.data.data.opeRights;
            box.forEach((item) => {
              if (item.type === 1) {
                this.Box1.push(item)
              } else if (item.type === 2) {
                this.Box2.push(item)
              } else if (item.type === 3) {
                this.Box3.push(item)
              } else if (item.type === 4) {
                this.Box4.push(item)
              } else if (item.type === 5) {
                this.Box5.push(item)
              } else if (item.type === 6) {
                this.Box6.push(item)
              } else if (item.type === 7) {
                this.Box7.push(item)
              } else if (item.type === 8) {
                this.Box8.push(item)
              } else if (item.type === 9) {
                this.Box9.push(item)
              }
            });
            cb()
          }
        })
      },
    },

  }
</script>

<style scoped>
  .el_foot {
    width: 40%;
    text-align: center;
    margin: 40px auto;
  }

  .box {
    background: #fff;
    height: 100%;
    padding: 0 30px 50px 30px;
  }

  .p_title {
    padding: 10px 40px 10px 20px;
    overflow: hidden;
    margin: 0;
  }

</style>
